<template>
	<view class="">
		<view class="kxczxcstreszxr pd pt30 pm20 ">

			<view class="  ">
				<view class="pt10 pm10 display-flex fz30 z6">
					<view class="xczvrytxctrtr vertical-center tl">
						姓名:
					</view>
					<view class="z3 flex-1">
						<input v-model="fromdata.realName" type="text" class="kxcxzrtrtxr pl20" placeholder="请输入姓名" />
					</view>
				</view>
				<view class="pt10 pm10 display-flex fz30 z6">
					<view class="xczvrytxctrtr vertical-center tl">
						部门:
					</view>
					<view class="z3 flex-1">
						<input v-model="fromdata.deptName" type="text" class="kxcxzrtrtxr pl20" placeholder="请输入部门" />
					</view>
				</view>
				<view class="pt10 pm10 display-flex fz30 z6">
					<view class="xczvrytxctrtr vertical-center tl">
						职别:
					</view>
					<view class="z3 flex-1">
						<input v-model="fromdata.level" type="text" class="kxcxzrtrtxr pl20" placeholder="请输入职别" />
					</view>
				</view>
				<view class="pt10 pm10 display-flex fz30 z6">
					<view class="xczvrytxctrtr vertical-center tl">
						入厂日期:
					</view>
					<view class="z3 flex-1">
						<picker mode="date" @change="kxzcertxa">
							<view :class="fromdata.companyTime?'z3':'z9'"
								class=" fz26 kxcxzrtrtxr vertical-center tl pl20">
								{{fromdata.companyTime||'请选择入厂日期'}}
							</view>
						</picker>
					</view>
				</view>
				<view class="pt10 pm10 display-flex fz30 z6">
					<view class="xczvrytxctrtr vertical-center tl ab">
						申请离职日期:
					</view>
					<view class="z3 flex-1">
						<picker mode="date" @change="kxzcertxb">
							<view :class="fromdata.takeTime?'z3':'z9'"
								class=" fz26 kxcxzrtrtxr vertical-center tl pl20">
								{{fromdata.takeTime||'请选择离职日期'}}
							</view>
						</picker>
					</view>
				</view>
				<view class="pt10 pm10 display-flex fz30 z6">
					<view class="xczvrytxctrtr vertical-center tl ab">
						确认离职日期:
					</view>
					<view class="z3 flex-1">
						<picker mode="date" @change="kxzcertxc">
							<view :class="fromdata.leaveTime?'z3':'z9'"
								class=" fz26 kxcxzrtrtxr vertical-center tl pl20">
								{{fromdata.leaveTime||'请确认离职日期'}}
							</view>
						</picker>
					</view>
				</view>
				<view class="pt10 pm10 display-flex fz30 z6">
					<view class="xczvrytxctrtr  tl pt20">
						辞职原因:
					</view>
					<view class="z3 flex-1">
						<textarea v-model="fromdata.content" placeholder="请输入辞职原因" class="zxrewtrt" />
					</view>
				</view>
			</view>
			<view class="tr btm pt20 mt20" v-if="fromdata.isPass!=1">


				<button v-if="fromdata.isPass==3" type="primary" size="mini" @tap="bjhxdfrtx(2)">重新申请</button>
				<button type="primary" v-else size="mini" @tap="bjhxdfrtx">保存</button>

			</view>
		</view>
		<view class="mt20 z9 pd red" v-if="fromdata.isPass==3">
			审核不通过: {{fromdata.passContent}}
		</view>
		<view class="mt20 z9 pd red ls" v-if="fromdata.isPass==2">
			已通过
		</view>
		<view class="mt20 z9 pd  z9" v-if="fromdata.isPass==1">
			等待审核
		</view>
	</view>
</template>
<script lang="ts" setup>
	import { ref } from "vue"
	import { hf, hfer, hfsan, dxrequest, VerifyTheLogin, upImg, yzphone, zidianall, transferTimeYMD, callBack } from "@/util/index.js"
	import { onLoad } from "@dcloudio/uni-app"
	const ret = ref()
	const fromdata = ref({
		realName: "",
		deptName: "",// 部门名称
		level: "",// 职别
		companyTime: "",//入厂日期
		takeTime: "",// 申请离职时间
		leaveTime: "",// 确定离职时间  
		content: "",
		type: 4
	})
	const kxzcertxa = (data) => {
		fromdata.value.companyTime = data.detail.value
	}
	const kxzcertxb = (data) => {
		fromdata.value.takeTime = data.detail.value
	}
	const kxzcertxc = (data) => {
		fromdata.value.leaveTime = data.detail.value
	}
	const getuser = async () => {
		const openid = uni.getStorageSync("openid")
		const { data } = await dxrequest("/api/user/" + openid)
		ret.value = data
		fromdata.value.realName = data.realName
		fromdata.value.companyTime = transferTimeYMD(data.companyTime)
	}
	getuser()
	const bjhxdfrtx = async (ty) => {
		if (!fromdata.value.takeTime) {
			uni.showToast({
				title: "请选择申请离职时间",
				icon: "none"
			})
			return
		}
		if (!fromdata.value.leaveTime) {
			uni.showToast({
				title: "请确定离职时间",
				icon: "none"
			})
			return
		}
		if (!fromdata.value.content) {
			uni.showToast({
				title: "请输入离职原因",
				icon: "none"
			})
			return
		}
		fromdata.value.companyId = ret.value.companyId
		fromdata.value.companyName = ret.value.companyName
		let kms = "post"
		if (fromdata.value.id) {
			kms = "put"
		}
		uni.showLoading({
			title: "加载中..."
		})
		if(ty==2){
			fromdata.value.isPass = 1
		}
		const xfd = await dxrequest("/api/userdata", fromdata.value, kms)
		uni.hideLoading()
		callBack()
	}
	const kmxcdf = async () => {
		const { data } = await dxrequest("/api/userdata/page", {
			type: 4
		})
		try {
			if (data.list[0].realName) {
				fromdata.value = data.list[0]
			}
		} catch (e) {

		}

	}
	kmxcdf()
</script>

<style scoped>
</style>